import { ref, computed } from "vue";
import { defineStore } from "pinia";
import { api_get_shop_classify } from "@/service/api/menu";

export const use_category_store = defineStore("category_store", {
  state: (): any => {
    return {
      category: [],
      history_search: [],
    };
  },

  getters: {
    get_hot_category(): category[] {
      let hot_category: category[] = [];
      if (this.category.length > 0) {
        this.category.forEach((item: category) => {
          hot_category.push(...item.children!.slice(0, 1));
        });
      }
      return hot_category;
    },
  },
  actions: {},
  persist: true,
});

interface state {
  category: category[];
}

interface category {
  createdAt: string;
  id: number;
  key: number;
  label: string;
  name: string;
  parent_id?: number;
  path: string;
  project_id: number;
  sort: string;
  status: string;
  thumb_url: null | string;
  updatedAt: string;
  user_id: number;
  value: number;
  children?: category[];
}
